package com.csun.cmny.provider.controller.admin;

import com.csun.cmny.core.support.BaseController;
import com.csun.cmny.provider.model.domain.DmcRfidEvent;
import com.csun.cmny.provider.model.dto.rfid.RfidEventOldmanQueryDto;
import com.csun.cmny.provider.model.dto.rfid.RfidEventPageQuery;
import com.csun.cmny.provider.model.vo.rfid.DmcRfidEventOldmanVo;
import com.csun.cmny.provider.resolver.CmnyMessageSource;
import com.csun.cmny.provider.service.DmcRfidEventOldmanService;
import com.csun.cmny.provider.service.DmcRfidEventService;
import com.csun.cmny.util.PublicUtil;
import com.csun.cmny.util.wrapper.WrapMapper;
import com.csun.cmny.util.wrapper.Wrapper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2019-01-22 14:58
 * @Description: the class dmc rfid event controller
 */
@RestController
@RequestMapping(value = "/rfidEvent", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class DmcRfidEventController extends BaseController {

    @Resource
    private DmcRfidEventService dmcRfidEventService;
    @Resource
    private DmcRfidEventOldmanService dmcRfidEventOldmanService;
    @Resource
    private CmnyMessageSource cmnyMessageSource;

    /**
     * @date    2019-09-12
     * @author  chisj
     * @desc    接口调整
     */
    //@LogAnnotation
    @RequestMapping(value = "/queryDmcRfidEventWithRoleListWithPage", method = RequestMethod.POST)
    public Wrapper queryDmcRfidEventListWithPage(@RequestBody RfidEventPageQuery rfidEventPageQuery) {

        rfidEventPageQuery.setGroupId(getLoginAuthDto().getGroupId());

        List<DmcRfidEvent> dmcRfidEventList = dmcRfidEventService.queryDmcRfidEventListWithPage(rfidEventPageQuery);

       // return WrapMapper.ok(new PageInfo<>(dmcRfidEventList));
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),new PageInfo<>(dmcRfidEventList));
    }

    /**
     * @date    2021-06-28
     * @author  HD
     * @desc    接口调整（根据卡类型查询出入信息）
     */
    //@LogAnnotation
    @RequestMapping(value = "/queryDmcRfidEventWithRoleListWithPageByRoleName", method = RequestMethod.POST)
    public Wrapper queryDmcRfidEventListWithPageByRoleName(@RequestBody RfidEventPageQuery rfidEventPageQuery) {

        rfidEventPageQuery.setGroupId(getLoginAuthDto().getGroupId());
        //rfidEventPageQuery.setGroupId(1001L);
        List<DmcRfidEvent> dmcRfidEventList = dmcRfidEventService.queryDmcRfidEventListWithPageByRoleName(rfidEventPageQuery);

        // return WrapMapper.ok(new PageInfo<>(dmcRfidEventList));
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),new PageInfo<>(dmcRfidEventList));
    }


    /**
     * 查询门禁记录
     */
    @RequestMapping(value = "/queryDmcRfidEventListWithPage", method = RequestMethod.POST)
    public Wrapper queryDmcRfidEventListWithPage(@RequestBody RfidEventOldmanQueryDto rfidEventOldmanQueryDto) {

        rfidEventOldmanQueryDto.setGroupId(getLoginAuthDto().getGroupId());
        rfidEventOldmanQueryDto.setOrderBy("created_time desc");

        List<DmcRfidEventOldmanVo> dmcRfidEventOldmanVoList = dmcRfidEventOldmanService
                .queryListWithPage(rfidEventOldmanQueryDto);

      //  return WrapMapper.ok(new PageInfo<>(dmcRfidEventOldmanVoList));
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),new PageInfo<>(dmcRfidEventOldmanVoList));
    }
}
